function out() {
    $.ajax({
        url: "index.php?c=user/userdo",
        type: "post",
        data: {type: "out"},
        dataType: "text",
        success: function (date) {
            location.reload();
        }
    });
}
function Myalert(i,v,c) {
    var a = document.getElementsByName("alert");
    a[i].innerHTML = v;
    a[i].style.color = c;
}
function hrefs(url) {
    location.href=url;
}
function login(user,pasw,code) {
    $.ajax({
        url: "index.php?c=user/userdo",
        type: "post",
        data: {type: "login", user: user, pasw: pasw, code:code},
        dataType: "text",
        success: function (date) {
            if (date == 0){
                location.href = "index.php?c=user/index";
            }
            else if(date == 2){
                alert("验证码错误！")
            }
            else
                alert("账号/密码错误！")
        }
    });
}
function isname(name,i) {
    if(name!="")
        $.ajax({
            url:"index.php?c=user/userdo",
            type:"post",
            data:{type:"isname",user:name},
            dataType:"text",
            success:function (date) {
                if(date==0)
                    Myalert(i,"账号可以使用","green");
                else
                    Myalert(i,"账号以被使用","red");
            }
        });
    else
        Myalert(i,"请填写账号","red");
}
function register(user,pasw) {
    $.ajax({
        url:"index.php?c=user/userdo",
        type:"post",
        data:{type:"register",user:user,pasw:pasw},
        dataType:"text",
        success:function (date) {
            if(date==0)
                alert("注册成功！");
            else
                alert("注册失败！")
        }
    });
}
function add(user,pasw) {
    $.ajax({
        url:"index.php?c=user/userdo",
        type:"post",
        data:{type:"register",user:user,pasw:pasw},
        dataType:"text",
        success:function (date) {
            if(date==0){
                alert("添加成功！");
                location.reload();
            }
            else
                alert("添加失败！");
        }
    });
}
function password(user,pasw,i) {
    if(user=="")
        return;
    var str = new RegExp(user);
    if(str.test(pasw))
        Myalert(i,"密码不能包含账号！","red");
    else if(pasw.length<6 || pasw.length>26)
        Myalert(i,"密码不小于6个字符且不大于26个字符！","red");
    else
        Myalert(i,"密码可以使用","green");
}
function update() {
    $("#form").ajaxSubmit({
        type:"post",
        dataType:"text",
        success:function (date) {
            if(date == 1)
                alert("修改失败");
            else{
                alert("修改成功");
                location.reload();
            }

        }
    });
}
function select(i) {
    //onclick=""
    //alert(i);
    $('#update').removeClass('sr-only');
    $.ajax({
        url:"index.php?c=user/userdo",
        type:"post",
        data:{type:"select",id:i},
        dataType:"json",
        success:function (date) {
           if(date.state==1){
               alert("系统繁忙");
           }
           else{
                $("#name").val(date.name);
                $("#id").val(date.id);
                $("#remarks").val(date.remarks);
           }
        }
    });
}
function mydelete() {
    if($("#id").val() == 1){
        alert("管理员不能删除");
        return;
    }
    if(confirm("你确定要删除它？")){
        $.ajax({
            url:"index.php?c=user/userdo",
            type:"post",
            data:{type:"delete",id:$("#id").val()},
            dataType:"text",
            success:function (date) {
                alert(date);
                if(date==1){
                    alert("删除失败");
                }
                else{
                    alert("删除成功");
                    location.reload();
                }
            }
        });
    }
}